package edu.xmut.kakamusic.fragment.login;

import android.os.Bundle;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.google.android.material.checkbox.MaterialCheckBox;
import com.google.android.material.snackbar.Snackbar;

import edu.xmut.kakamusic.R;
import edu.xmut.kakamusic.databinding.FragmentLoginMainBinding;
import edu.xmut.kakamusic.utils.SnackBarUtil;


public class LoginMainFragment extends Fragment {


    private ConstraintLayout root;
    private MaterialCheckBox cbLoginReadMain;
    private Button btnLoginMain;
    private Snackbar snackbar;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        FragmentLoginMainBinding binding = FragmentLoginMainBinding.inflate(inflater, container, false);
        root = binding.getRoot();
        initView();

        return root;
    }

    private void initView() {
        btnLoginMain = root.findViewById(R.id.btn_login_main);
        cbLoginReadMain = root.findViewById(R.id.cb_login_read_main);
        btnLoginMain.setOnClickListener(this::login);
    }

    private void login(View view) {
        if (cbLoginReadMain.isChecked()) {
            NavController navController = Navigation.findNavController(root);
            navController.navigate(R.id.action_loginMainFragment_to_loginDetailFragment);
        } else {
            snackbar = SnackBarUtil.showSnackBar(requireActivity(), view, "请先阅读并同意《用户协议》《隐私协议》", true, R.drawable.baseline_close_24, new ISnackBarClickEventImpl());
        }

    }

    class ISnackBarClickEventImpl implements SnackBarUtil.ISnackBarClickEvent {
        @Override
        public void tvClickEvent() {

        }

        @Override
        public void imgClickEvent() {
            snackbar.dismiss();
        }
    }


}

